package com.taoxi.shops.controller;

import com.taoxi.common.annotation.Anonymous;
import com.taoxi.common.annotation.Log;
import com.taoxi.common.core.controller.BaseController;
import com.taoxi.common.core.domain.AjaxResult;
import com.taoxi.common.core.page.TableDataInfo;
import com.taoxi.common.enums.BusinessType;
import com.taoxi.common.utils.poi.ExcelUtil;
import com.taoxi.shops.domain.Wholesaler;
import com.taoxi.shops.service.IWholesalerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 批发商管理Controller
 *
 * @author ruoyi
 * @date 2024-10-24
 */
@Api(tags = "批发商管理Controller")
@RestController
@RequestMapping("/shops/wholesaler")
public class WholesalerController extends BaseController {
    @Autowired
    private IWholesalerService wholesalerService;

    /**
     * 查询批发商管理列表
     */
    @ApiOperation("查询批发商管理列表")
    @PreAuthorize("@ss.hasPermi('shops:wholesaler:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wholesaler wholesaler) {
        startPage();
        List<Wholesaler> list = wholesalerService.selectWholesalerList(wholesaler);
        return getDataTable(list);
    }

    /**
     * 导出批发商管理列表
     */
    @ApiOperation("导出批发商管理列表")
    @PreAuthorize("@ss.hasPermi('shops:wholesaler:export')")
    @Log(title = "批发商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Wholesaler wholesaler) {
        List<Wholesaler> list = wholesalerService.selectWholesalerList(wholesaler);
        ExcelUtil<Wholesaler> util = new ExcelUtil<Wholesaler>(Wholesaler.class);
        util.exportExcel(response, list, "批发商管理数据");
    }

    /**
     * 获取批发商管理详细信息
     */
    @ApiOperation("获取批发商管理详细信息")
    @PreAuthorize("@ss.hasPermi('shops:wholesaler:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wholesalerService.selectWholesalerById(id));
    }

    /**
     * 新增批发商管理
     */
    @ApiOperation("新增批发商管理")
    @PreAuthorize("@ss.hasPermi('shops:wholesaler:add')")
    @Log(title = "批发商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wholesaler wholesaler) {
        return toAjax(wholesalerService.insertWholesaler(wholesaler));
    }

    /**
     * 修改批发商管理
     */
    @ApiOperation("修改批发商管理")
    @PreAuthorize("@ss.hasPermi('shops:wholesaler:edit')")
    @Log(title = "批发商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wholesaler wholesaler) {
        return toAjax(wholesalerService.updateWholesaler(wholesaler));
    }

    /**
     * 删除批发商管理
     */
    @ApiOperation("删除批发商管理")
    @PreAuthorize("@ss.hasPermi('shops:wholesaler:remove')")
    @Log(title = "批发商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wholesalerService.deleteWholesalerByIds(ids));
    }

    /**
     * 查询批发商销量排序
     */
    @Anonymous
    @ApiOperation("批发商销量排序")
    @GetMapping("/getSalesSort")
    public TableDataInfo getSalesSort(Wholesaler wholesaler) {
        startPage();
        List<Wholesaler> list = wholesalerService.getSalesSort(wholesaler);
        return getDataTable(list);
    }
}
